<?php

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

class Doctrine {

    // Doctrine实体管理器
    /**
     *
     * @var \Doctrine\ORM\EntityManage 
     */
    public $em = null;

    public function __construct() {

        // 导入CI的数据库配置
        require_once APPPATH . 'config/database.php';
        $paths = [
            APPPATH . 'models'
        ];

        $isDevMode = true;

        // the connection configuration
        $connectionOptions = array(
            'driver' => 'pdo_mysql',
            'user' => $db['default']['username'],
            'password' => $db['default']['password'],
            'host' => $db['default']['hostname'],
            'dbname' => $db['default']['database']
        );

        $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
        $this->em = EntityManager::create($connectionOptions, $config);
    }
    
    /**
     * 
     * @return \Doctrine\ORM\EntityManager
     */
    function getManager(){
        return $this->em;
    }
}
